package com.web.controller;

import com.web.bean.学生情况;
import com.web.dao.学生情况Dao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet("/updateStudent")
public class StudentUpdateController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");

        String sid = req.getParameter("id");
        String 姓名 = req.getParameter("姓名");
        String 性别 = req.getParameter("性别");
        String 出生日期 = req.getParameter("出生日期");
        String 政治面貌 = req.getParameter("政治面貌");
        String 生源地 = req.getParameter("生源地");
        String 院系代号 = req.getParameter("院系代号");
        String 宿舍电话 = req.getParameter("宿舍电话");
        System.out.println(sid);

        学生情况 stu = new 学生情况(sid, "1", "1", "1", "1", "1", "1",1, "1",null);

        学生情况Dao dao = new 学生情况Dao();
        boolean isok = false;
        try {
            isok = dao.updateStu(stu);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        if (isok) {
            req.getRequestDispatcher("/getAllStudent").forward(req, resp);
        } else {

            req.setAttribute("message", "修改操作失败，请重新操作");
            req.setAttribute("stu", stu);

            req.getRequestDispatcher("/StudentUpdate.jsp").forward(req, resp);
        }
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}